﻿using WindowsForms.AOnline.Model.BusinessObjects.Dictionary;
using WindowsForms.AOnline.Presenter.Dictionary.Account;
using WindowsForms.AOnline.View.Dictionary;
//using System.Threading.Tasks;

namespace WindowsForms.AOnline.Presenter.Dictionary.Customer
{
    public class CustomerPresenter : Presenter<ICustomerView>  
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountPresenter" /> class.
        /// </summary>
        /// <param name="view">The view.</param>
        public CustomerPresenter(ICustomerView view)
            : base(view)
        {
        }

        /// <summary>
        /// Displays the specified employ identifier.
        /// </summary>
        /// <param name="employId">The employ identifier.</param>
        public void Display(string employId) 
        {
            if (employId == null) { View.CustomerId = 0; return; }
            var employ = Model.GetCustomer(int.Parse(employId));
          //  View.CustomerId = employ.EmployId;
          //  View.CompanyName = employ.Name;
            //View.Code = employ.Salary;
            //View.DepartmentId = employ.DepartmentId;

            View.CustomerId = employ.CustomerId;
            View.UnitId = employ.UnitId;
          View.Code = employ.Code;
           View.CustomerName = employ.Name;
            View.Address = employ.Address;
            View.PhoneNumber = employ.PhoneNumber;
             View.Fax = employ.Fax;
            View.CompanyName = employ.CompanyName;
            View.ContactName = employ.ContactName;
           View.Description = employ.Description;
           View.IsActive = employ.IsActive;
        }

        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns>System.Int32.</returns>
        public string Save()
        {
            var customer = new CustomerModel     
            {
               CustomerId = View.CustomerId,
            UnitId = View.UnitId,
            Code = View.Code,
            Name = View.CustomerName,
            Address = View.Address,
            PhoneNumber = View.PhoneNumber,
            Fax = View.Fax,
            CompanyName = View.CompanyName,
            ContactName = View.ContactName,
            Description = View.Description,
            IsActive = View.IsActive,
            };

            if (View.CustomerId == 0)
                return Model.AddCustomer(customer);
            return Model.UpdateCustomer(customer);
        }

        /// <summary>
        /// Deletes the specified employ identifier.
        /// </summary>
        /// <param name="employId">The employ identifier.</param>
        /// <returns>System.Int32.</returns>
        public string Delete(int employId) 
        {
            return Model.DeleteCustomer(employId);
        }
    }
}
